?><?
$control_tags=array();
class cls_filter_control extends cls_filter{
  function process_html($object,$html){
    $html=preg_replace_callback("|\{control(.*?)\}|i","filter_collect_controls",$html);
    global $control_tags;
    foreach($control_tags as $key=>$tag){
      $tag_params=array();
      $idx=0;
      $token=strtok($tag,"=\"");
      $name="";
      $value="";
      do{
        if($idx++%2==0){
          $name=trim($token);
        }else{
          $tag_params[$name]=trim($token);
        }
      }while($token=strtok("=\""));
      $control_code=$this->insert_control($tag_params);
      $html = str_replace("%%CONTROL(".$key.")%%",$control_code,$html);
    }
    return $html;
  }

  function insert_control($tag_params){
    $name=gav($tag_params,"name");
    if($control=get_control($name)){
      ob_start();
      clear_url_override();
      set_controls_url();
      $control->content();
      restore_url_override();
      $content=ob_get_clean();
    }
    return $content;
  }

}


function filter_collect_controls($matches){
  global $control_tags;
  $control_tags[]=$matches[1];
  return "%%CONTROL(".(count($control_tags)-1).")%%";
}

$filters[]="cls_filter_control";